//
//  LaunchView.m
//  cold jest
//
//  Created by wxhl on 13-3-14.
//  Copyright (c) 2013年 无限互联IOS培训第三期. All rights reserved.
//

#import "LaunchView.h"
#import "MainViewController.h"

@implementation LaunchView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self view];
    }
    return self;
}
- (void)addImageView:(NSNumber *)countNumber
{
    MyNSLog("%g", kScreenHeight);
    UIScrollView * scrollView = [[UIScrollView alloc]init];
    if (kScreenHeight == 480) {
        scrollView.frame = CGRectMake(0, 0, 320, 480);
        scrollView.contentOffset = CGPointMake(0, 0);
        scrollView.contentSize = CGSizeMake(320*5, 480);
    }else if (kScreenHeight == 568){
        scrollView.frame = CGRectMake(0, 0, 320, 568);
        scrollView.contentOffset = CGPointMake(0, 0);
        scrollView.contentSize = CGSizeMake(320*5, 568);
    }else{
        scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        scrollView.contentOffset = CGPointMake(0, 0);
        scrollView.contentSize = CGSizeMake(kScreenWidth*5, kScreenHeight);
    }
    scrollView.pagingEnabled = YES;
    scrollView.directionalLockEnabled = YES;
    scrollView.delegate = self;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.bounces = NO;
    [self addSubview:scrollView];
    
    for (int index = 0; index <=4; index++) {
        
        if (kScreenHeight == 480) {
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(320 * index, 0, 320, 480)];
            if (index < 5){
                imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"启动页%d@2x.png",index+1]];
            }else if (kScreenWidth == 568){
                imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"启动页%d@2x.png",index+1]];
            }else{
                imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"启动页%d@2x.png",index+1]];

            }
            [scrollView addSubview:imageView];
            UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(320*5 - 282/2 - 92, 480-23- 40 - 51 , 282/2, 40)];
            logoImageView.image = [UIImage imageNamed:@"进入按钮@2x"];
            logoImageView.userInteractionEnabled = YES;
            [scrollView addSubview:logoImageView];
            UITapGestureRecognizer * tipSing = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(putInto:)];
            [logoImageView addGestureRecognizer:tipSing];
            
        }else if (kScreenHeight == 568){
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(320 * index, 0, 320, 568)];
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"启动页5S%d@2x.png",index+1]];
            [scrollView addSubview:imageView];
            UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(320*5 - 282/2 - 91.001, 568-23- 40 - 51 - 59 , 282/2, 40)];
            logoImageView.image = [UIImage imageNamed:@"进入按钮@2x"];
            logoImageView.userInteractionEnabled = YES;
            [scrollView addSubview:logoImageView];
            UITapGestureRecognizer * tipSing = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(putInto:)];
            [logoImageView addGestureRecognizer:tipSing];
        }else{
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth * index, 0, kScreenWidth, kScreenHeight)];
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"启动页5S%d@2x.png",index+1]];
            [scrollView addSubview:imageView];
            UIImageView * logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth*5 - 282/2 - (kScreenWidth - 282/2)/2 , kScreenHeight-23- 40 - 51 - 59 , 282/2, 40)];
            logoImageView.image = [UIImage imageNamed:@"进入按钮@2x"];
            logoImageView.userInteractionEnabled = YES;
            [scrollView addSubview:logoImageView];
            UITapGestureRecognizer * tipSing = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(putInto:)];
            [logoImageView addGestureRecognizer:tipSing];
        }
    }
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(kScreenWidth - 55, 29, 60, 30);
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitle:@"跳过" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:button];
    
    UIButton * button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 addTarget:self action:@selector(tiaoguo) forControlEvents:UIControlEventTouchUpInside];
    button1.frame = CGRectMake(kScreenWidth - 65, 25, 80, 45);
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button1.titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:button1];
    
}
- (void)view
{
    self.backgroundColor = [UIColor clearColor];
    [self addImageView:[NSNumber numberWithInt:0]];
}
- (void)tiaoguo
{
    if ([self.delegate respondsToSelector:@selector(launchViewDidFinish:)]) {
        [self.delegate launchViewDidFinish:self];
    }
    
}
- (void)putInto:(UIGestureRecognizer *)tipsing
{
    if ([self.delegate respondsToSelector:@selector(launchViewDidFinish:)]) {
        [self.delegate launchViewDidFinish:self];
    }
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

@end
